package com.offer;


import java.util.ArrayList;

public class Test63 {

    public int maxProfit(int[] prices) {
        if (prices.length <= 0) {
            return 0;
        }

        if (prices.length == 1) {
            return 0;
        }

        int maxProfit = 0;
        int minPrice = prices[0];

        for (int i = 1; i < prices.length; i++) {
            if (minPrice > prices[i]) {
                minPrice = prices[i];
            } else {
                maxProfit = Math.max(maxProfit, prices[i] - minPrice);
            }
        }

        return maxProfit;
    }

    public static void main(String[] args) {
        Test63 test = new Test63();
        System.out.println(test.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }

}
